<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class OrderRiskBoolea extends Model
{
    protected $table = "sp_order_risk_boolea";
    protected $primaryKey = 'id';
    public $timestamps = false;

    //查询风控信息
    protected function getRiskData($order_id)
    {
        $data = $this
            ->where('order_id',$order_id)
            ->where("end_at",">",date('Y-m-d H:i:s',time()))
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    protected function getRiskNewsData($order_id)
    {
        $data = $this
            ->where('order_id',$order_id)
            ->orderby('id','desc')
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    protected function getRiskHistoryData($order_id)
    {
        $data = $this
            ->where('order_id',$order_id)
            ->orderby('id','asc')
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }
    //商户查询风控信息
    protected function getMemberRiskData($order_id,$member)
    {
        $data = $this
            ->where('order_id',$order_id)
            ->where('member_id',$member)
            ->where("end_at",">",date('Y-m-d H:i:s',time()))
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加风控信息
    protected function setRiskData($order_id,$result)
    {
        $risk_data['order_id'] = $order_id;
        $risk_data['result'] = json_encode($result);
        $t = $result['timestamp'];

        $risk_data['start_at'] = date('Y-m-d H:i:s',time());
        $risk_data['end_at'] =  date('Y-m-d H:i:s',time()+7*24*60*60);

        $this->insert($risk_data);

        return true;
    }

    //编辑风控信息
    protected function editRiskData($order_id,$risk_data)
    {
        $this->where('order_id',$order_id)->update($risk_data);

        return true;
    }

    //添加风控其他信息
    protected function insertRiskData($order_id,$data)
    {
        $risk_data['order_id'] = $order_id;

        $this->insert($data);

        return true;
    }

}
